package ensib.sti.ssu.activities;

import java.util.Calendar;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.TextView;

public class PickDateActivity extends Activity {
	private int mYear;
	private int mMonth;
	private int mDay;

	 

	static final int DATE_DIALOG_ID = 0xBAB;
	private DatePickerDialog.OnDateSetListener mDateSetListener 
		       ;
	@SuppressLint("InlinedApi")
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		final Calendar c = Calendar.getInstance();
	    mYear = c.get(Calendar.YEAR);
	    mMonth = c.get(Calendar.MONTH);
	    mDay = c.get(Calendar.DAY_OF_MONTH);
	    mDateSetListener =
			    new DatePickerDialog.OnDateSetListener() {
			        public void onDateSet(DatePicker view, int year, 
			                              int monthOfYear, int dayOfMonth) {
			            mYear = year;
			            mMonth = monthOfYear;
			            mDay = dayOfMonth;
			           PickDateActivity.this. finish();
			        }
			    };
		//showDialog(DATE_DIALOG_ID);
			    new DatePickerDialog(this,DatePickerDialog.THEME_HOLO_LIGHT,
		                mDateSetListener,
		                mYear, mMonth, mDay).show();
	    

	}
	/*@Override
	protected Dialog onCreateDialog(int id) {
	   switch (id) {
	   case DATE_DIALOG_ID:
	      return new DatePickerDialog(this,
	                mDateSetListener,
	                mYear, mMonth, mDay);
	   }
	   return null;
	}*/
	@Override
	public void finish() {
		// TODO Auto-generated method stub
		Intent t=new Intent();
		Bundle b=new Bundle();
		b.putString("date", new StringBuilder()
       
		 .append(mDay).append("/")
        .append(mMonth + 1).append("/")
       
        .append(mYear).toString());
		t.putExtras(b);
		setResult(RESULT_OK, t);
		super.finish();
	}
}
